// 当前函数，用于角色的删除功能
function delRole(id) {
    if (confirm(`你确定要删除id为${id}的角色吗？`)) {
        axios.delete('/roles/' + id).then(() => {
            let nn = $('#' + id);
            nn.remove();
        });
        // $.ajax({
        //     url:'/roles'+id,
        //     method:'delete'
        // })
    }
}

function redirectEditRole(id) {
    location.href = '/roleEdit/' + id;
}

function save(id) {
    let rolename = $('[name=rolename]').val();
    if (id) {        
        axios.put('/roles/' + id, { rolename }).then((res) => {
            console.log(res);
            location.href = '/roles'
        })
    } else {
        axios.post('/roles', { rolename }).then((res) => {
            console.log(res);
            location.href = '/roles'
        })
    }

}

function cancle() {
    location.href = '/roles'
}

function addRole() {
    location.href = '/roleEdit';
}